#include <stdio.h>
#include <string.h>
#include <pthread.h>

#include "calc.h"
#include "sort.h"

static void* thread_func(void *arg)
{
	printf("[%s:%d] enter pthread func\n", __FUNCTION__, __LINE__);
	
	int i = 10;
	while(i > 0)
	{
		printf("[%s:%d] i = %d\n", __FUNCTION__, __LINE__, i);
		i--;
	}

	
	return NULL;
}


int main(int argc, char* argv[])
{
	int a = 10, b = 3;
	
	printf("[%s:%d] a = %d, b = %d\n", __FUNCTION__, __LINE__, a, b);
    printf("[%s:%d] a + b = %d\n", __FUNCTION__, __LINE__, add(a, b));
    printf("[%s:%d] a - b = %d\n", __FUNCTION__, __LINE__, sub(a, b));
    printf("[%s:%d] a * b = %d\n", __FUNCTION__, __LINE__, mult(a, b));
    printf("[%s:%d] a / b = %f\n", __FUNCTION__, __LINE__, div(a, b));
	
	insert(a, b);
	select(a, b);
	
#if defined(TEST_NUM)
	printf("[%s:%d] TEST_NUM = %d\n", __FUNCTION__, __LINE__, TEST_NUM);
#endif 
	
#if defined(DEBUG_ENA) && (DEBUG_ENA != 0)
	printf("[%s:%d] DEBUG_ENA = %d\n", __FUNCTION__, __LINE__, DEBUG_ENA);
#endif 
	
	pthread_t test_pthread;
    //pthread_attr_t pth_attr;
    //pthread_attr_init(&pth_attr);
    //pthread_attr_setdetachstate(&pth_attr, PTHREAD_CREATE_DETACHED);

    int ret = pthread_create(&test_pthread, NULL, thread_func, NULL);
    if (ret != 0)
    {
		printf("[%s:%d] pthread create failed\n", __FUNCTION__, __LINE__);
    }
    else
    {
		printf("[%s:%d] pthread create OK\n", __FUNCTION__, __LINE__);
    }
	
	//pthread_attr_destroy(&pth_attr);
	pthread_join(test_pthread, NULL);

	return 0;
}
